package com.example.curriculum;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class login_byaccount extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // 关联activity.xml
        setContentView(R.layout.activity_login_byaccount);
        // 关联用户名、密码和登录、注册按钮
        EditText userName = (EditText) this.findViewById(R.id.et_user_name);
        EditText passWord = (EditText) this.findViewById(R.id.et_psw);
        Button loginButton = (Button) this.findViewById(R.id.btn_login);
        Button signUpButton = (Button) this.findViewById(R.id.tv_register);
        // 登录按钮监听器
        loginButton.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        // 获取用户名和密码
                        String strUserName = userName.getText().toString().trim();
                        String strPassWord = passWord.getText().toString().trim();
                        if (strUserName.equals("12345678") && strPassWord.equals("123456")) {
                            Intent intent = new Intent(login_byaccount.this, MainActivity.class);
                            startActivity(intent);
                        } else {
                            Toast.makeText(login_byaccount.this, "请输入正确的用户名或密码！", Toast.LENGTH_SHORT).show();
                        }
                    }
                }
        );
        // 注册按钮监听器
        signUpButton.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        // 跳转到注册界面
                        Intent intent = new Intent(login_byaccount.this, SignUp.class);
                        startActivity(intent);
                    }
                }
        );

    }
}